<?php

/**
* Chargement des classes de base
*/
$classes_path = dirname ( __FILE__ ) ;

if ( is_dir ( $classes_path ) )
{
	if ( $system_folder = opendir ( $classes_path ) )
	{
		while ( ( $class_file = readdir ( $system_folder ) ) !== false )
		{
			
			if ( ! in_array ( $class_file, array ( '.', '..' ) ) && substr ( $classes_path . $class_file, -10 ) === '.class.php' && $classes_path . '\\' . $class_file !== __FILE__ )
			{
				include $classes_path . '/' . $class_file ;
			}
		}
		closedir ( $system_folder ) ;
	}
}

unset ( $class_file, $system_folder, $classes_path ) ;

abstract class System
{
	
	public static function ApacheModuleLoaded ( $mod )
	{
		
		return in_array ( $mod, apache_get_modules ( ) ) ;
		
	}
	
	public static function urlTo ( $controller = NULL, $action = NULL, $params = array ( ) )
	{
		
		$url = '' ;
		
		if ( $controller != NULL )
		{
			
			if ( System::ApacheModuleLoaded ( 'mod_rewrite' ) )
			$url = $controller ;
			else
			$url = 'index.php?url=/' . $controller ;
			
		}
		
		if ( $action != NULL )
		{
				
			$url .= '/' . $action ;
				
			foreach ( $params as $param )
			{
				$url .= '/' . $param ;
			}
				
		}
		
		return BASE . '/' . $url ;
		
	}
	
	public static function redirectTo ( $controller = NULL, $action = NULL, $params = array ( ) )
	{
		
		header ( 'Location: ' . self::urlTo ( $controller, $action, $params ) ) ;
		exit ;
		
	}
	
}

?>